package com.yan.yjhTest.collection.map;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

public class HashMapTest {

    public static void main(String[] args) {
        HashMapThread thread0 = new HashMapThread();
        HashMapThread thread1 = new HashMapThread();
        HashMapThread thread2 = new HashMapThread();
        HashMapThread thread3 = new HashMapThread();
        HashMapThread thread4 = new HashMapThread();
        HashMapThread thread5 = new HashMapThread();
        HashMapThread thread6 = new HashMapThread();
        HashMapThread thread7 = new HashMapThread();
        HashMapThread thread8 = new HashMapThread();
        HashMapThread thread9 = new HashMapThread();
        HashMapThread thread10 = new HashMapThread();
        thread0.start();
        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
        thread5.start();
        thread6.start();
        thread7.start();
        thread8.start();
        thread9.start();
        thread10.start();
    }
}

class HashMapThread extends Thread {
    private static AtomicInteger ai = new AtomicInteger();
    private static final Map<Integer, Integer> map = new HashMap<>();

    @Override
    public void run() {
        try{
            while (ai.get() < 1000000) {
                map.put(ai.get(), ai.get());
                ai.incrementAndGet();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
